package cn.itcast.travel.service.impl;

import cn.itcast.travel.dao.OrderDao;
import cn.itcast.travel.dao.RoutDao;
import cn.itcast.travel.dao.impl.OrderDaoImp;
import cn.itcast.travel.dao.impl.RoutDaoImp;
import cn.itcast.travel.domain.OrderDo;
import cn.itcast.travel.domain.Route;
import cn.itcast.travel.domain.vo.IndentVO;
import cn.itcast.travel.service.IndentService;

import java.util.ArrayList;
import java.util.List;

public class IndentServiceImpl implements IndentService {
    private OrderDao od = new OrderDaoImp();
    private RoutDao rd = new RoutDaoImp();
    @Override
    public List<IndentVO> getIndentVOByUid(String uid) {
        List<IndentVO> arr = new ArrayList<>();

        //根据订单号查询订单信息
        List<OrderDo> odb = od.getOrderDaoByUid(uid);
        for (OrderDo orderDo : odb) {
            IndentVO indentVO = new IndentVO();
            //设置支付状态
            indentVO.setIspay(orderDo.getIspay());
            //设置订单编号
            indentVO.setOut_trade_no(orderDo.getOut_trade_no());

            Route one = rd.findOne(orderDo.getRid());
            //设置线路名称
            indentVO.setName(one.getRname());
            //设置价格
            indentVO.setMoney(one.getPrice()+"");

            arr.add(indentVO);

        }

        return arr;
    }

    @Override
    public int findRidByout_trade_no(String out_trade_no) {
        return od.findRidByout_trade_no(out_trade_no);
    }
}
